/**
 * @author yan
 * @date 2025/7/30
 */
public class ti14 {
    class Solution {
        public String longestCommonPrefix(String[] strs) {
            if (strs.length <= 1){
                return strs[0];
            }
            else {
                int min = 100000;
                int s = 0;
                for(int i=0;i<strs.length;i++){
                    if (strs[i].length()<min) {
                        min = strs[i].length();
                        s=i;
                    }
                }
                for (int i = 0; i < min; i++) {
                    char c = strs[s].charAt(i);
                    for (int j = 0; j < strs.length; j++) {
                        char c1 = strs[j].charAt(i);
                        if (c == c1) {
                            continue;
                        } else {
                            return strs[0].substring(0, i);
                        }
                    }
                }
                return strs[0].substring(0, min);
            }
        }
    }
    public static void main(String[] args) {

    }
}
